package org.xlp.mvc.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xlp.mvc.context.ApplicationContext;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * Servlet 基础监听器，用来初始化bean上下文容器
 */
public abstract class BaseApplicationListener implements ServletContextListener {
    private static final Logger LOGGER = LoggerFactory.getLogger(BaseApplicationListener.class);

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        // 创建bean上下文容器
        try {
            ApplicationContext.create(this.getClass(), this.getClass().getClassLoader());
        } catch (Exception e) {
            if (LOGGER.isErrorEnabled()){
                LOGGER.error("创建bean上下文容器失败", e);
            }
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}
